<template>
  <div>
    用户首页，暂时通过按钮模拟功能
    <el-row>
      <el-button type="success" @click="shopcart">我的购物车</el-button>
      <el-button type="success" @click="productDetails">商品详情</el-button>
      <el-button type="success" @click="userAddress">用户地址</el-button>
      <el-button type="success" @click="userLogin">登录</el-button>
      <el-button type="success" @click="userLogout">退出</el-button>
    </el-row>
  </div>
</template>

<script>
import axios from 'axios'
import { userTokenStore } from '@/stores/index.js'
const userToken = userTokenStore()
export default {
  name: "index",
  methods:{
    //跳转购物车
    shopcart(){
      this.$router.push('/shopcart')
    },
    //跳转商品详情
    productDetails(){
      this.$router.push('/productDetails')
    },
    //跳转用户地址
    userAddress(){
      this.$router.push('/userAddress')
    },
    userLogin(){
      this.$router.push('/login')
    },
    userLogout(){
      console.log(userToken.token)
      axios({
        method:"get",
        url:'/admin/user/logout',
        headers:{
          token: userToken.token
        }
      }).then(res=>{
        console.log(res.data)
        if(res.data.code === 200){
          ElMessage.success('期待你的归来')
          userToken.delUserToken()
          this.$router.push('/login')
        }
      }).catch((error) => {
        console.log(error)
      });
    }
  }
}
</script>

<style scoped>
</style>
